Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Apr 10, 2025

having a more precise type helps to prevent false positives when implementing e.g. PHPStan rules

private function findInputTypeIdsInNew(New_ $newExpr, ClassReflection $class, Scope $scope): array
    {
        if (\count($newExpr->args) === 0) {
            // more logic
            return [];
        }

        $firstArg = $newExpr->args[0]; // Offset 0 might not exist on non-empty-array<PhpParser\Node\Arg|PhpParser\Node\VariadicPlaceholder>.
        if (! $firstArg instanceof Arg) {
            return [];
        }

happens when PHPStan is configured with reportPossiblyNonexistentGeneralArrayOffset

@staabm staabm marked this pull request as ready for review April 10, 2025 08:15
@nikic
Copy link
Owner

nikic commented Apr 10, 2025

This looks fine, but will this cause BC issues? I think people were concerned about that in the past.

@staabm
Copy link
Contributor Author

staabm commented Apr 11, 2025

yes, I had similar feelings when submitting the PR. When in doubt this PR has to wait for the next major version

@staabm
Copy link
Contributor Author

staabm commented Oct 31, 2025

@nikic today I stumbled over this again while working on phpstan-src.

do you think it makes sense merging?

@staabm
Copy link
Contributor Author

staabm commented Oct 31, 2025

alternatively (and more safe) we could re-activate https://github.com/phpstan/phpstan-php-parser to override the signatures in phpstan context

@staabm
Copy link
Contributor Author

staabm commented Oct 31, 2025

do it here instead: phpstan/phpstan-src#4503

@staabm staabm closed this Oct 31, 2025
@staabm staabm deleted the list branch October 31, 2025 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants